package com.tenement.service.impl;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.tenement.service.GaoDeService;
import com.tenement.vo.GaoDeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class GaoDeServiceImpl implements GaoDeService {

    @Value("${gaode.key}")
    private String key;

    //获取行政区划列表
    private static final String District = "https://restapi.amap.com/v3/config/district";


    private static final String GeoCodeRgeo = "https://restapi.amap.com/v3/geocode/regeo";

    private static final String WeatherInfo = "https://restapi.amap.com/v3/weather/weatherInfo";

    @Override
    public JSONObject getAreaInfo(GaoDeVo gaoDeVo) {
        return JSONObject.parseObject(HttpUtil.get(GeoCodeRgeo + "?key=" + key + "&location=" + gaoDeVo.getLongitude() + "," + gaoDeVo.getLatitude()));
    }

    @Override
    public JSONObject getBarrio(String keyWord) {
        return JSONObject.parseObject(HttpUtil.get(District + "?key=" + key + "&keywords=" + keyWord + "&subdistrict=3"));
    }

    @Override
    public JSONObject getWeatherInfo(GaoDeVo gaoDeVo) {
        return JSONObject.parseObject(HttpUtil.get(WeatherInfo + "?key=" + key + "&city=" + gaoDeVo.getAdCode() + "&extensions=" + gaoDeVo.getExtensions()));
    }


}
